﻿using System;
using System.Linq;
using System.Reflection;

namespace RanbuOM.Serialization
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public class DataPropertyAttribute : Attribute
    {
        public string Group { get; set; }

        public int SizeConst { get; set; }

        public static DataPropertyAttribute GetAttributeOrNull(ICustomAttributeProvider provider)
        {
            var attrs = provider.GetCustomAttributes(typeof(DataPropertyAttribute), false);
            if (attrs.Length > 1)
            {
                throw new InvalidOperationException("Redundant attributes found on " + provider.ToString());
            }

            return attrs.FirstOrDefault() as DataPropertyAttribute;
        }
    }
}
